<?php
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php')
);

return [
    'id'                  => 'api',
    'basePath'            => dirname(__DIR__),
    'bootstrap'           => ['log'],
    'controllerNamespace' => 'api\controllers',

    'components' => [
        'user'       => [
            'class'           => yii\web\User::className(),
            'identityClass'   => common\models\User::className(),
            'enableAutoLogin' => true,
            'enableSession'   => false,//禁用session
        ],
        'log'        => [//此项具体详细配置，请访问http://wiki.feehi.com/index.php?title=Yii2_log
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets'    => [
                [
                    'class'  => yii\log\FileTarget::className(),//当触发levels配置的错误级别时，保存到日志文件
                    'levels' => ['error', 'warning'],
                ],
                [
                    'class'   => yii\log\EmailTarget::className(),//当触发levels配置的错误级别时，发送到此些邮箱（请改成自己的邮箱）
                    'levels'  => ['error', 'warning'],
                    /*'categories' => [//默认匹配所有分类。启用此项后，仅匹配数组中的分类信息会触发邮件提醒（白名单）
                        'yii\db\*',
                        'yii\web\HttpException:*',
                    ],*/
                    'except'  => [//以下配置，除了匹配数组中的分类信息都会触发邮件提醒（黑名单）
                        'yii\web\HttpException:404',
                        'yii\web\HttpException:403',
                        'yii\debug\Module::checkAccess',
                    ],
                    'message' => [
                        'to'      => ['admin@feehi.com', 'mars167@icloud.com'],
                        'subject' => '来自 Feehi CMS api的新日志消息',
                    ],
                ],
            ],
        ],
        'cache'      => [
            'class'     => yii\caching\DummyCache::className(),
            'keyPrefix' => 'api',       // 唯一键前缀
        ],
        'urlManager' => [
            'enablePrettyUrl'     => true,
            'enableStrictParsing' => true,
            'showScriptName'      => false,
            'rules'               => [
//                'index' => 'site/index',
                'login'                   => 'user/login',
                'register'                => 'user/register',
                'profile'                 => 'user/profile',
                'collected/<id:\d+>'      => 'photo/collect',
                'mine/<id:\d+>'           => 'photo/mine',
                'fans-list/<id:\d+>'      => 'user/fans-list',
                'fellow-list/<id:\d+>'    => 'user/fellow-list',
                'push/<type:\d+>'         => 'photo/push',
                'update-avatar'           => 'user/update-info',
                'DELETE delete/<pid:\d+>' => 'collect/delete',
                [
                    'class'         => yii\rest\UrlRule::className(),
                    'controller'    => [
                        'article',
                    ],
                    'extraPatterns' => [
                        'POST search' => 'search'
                    ],
                ],
                [
                    'class'      => yii\rest\UrlRule::className(),
                    'controller' => 'photo'
                ],
                [
                    'class'         => yii\rest\UrlRule::className(),
                    'controller'    => 'user',
                    'except'        => ['delete', 'create',],
//		            'pluralize'=>false,
                    'extraPatterns' => [
                        'POST login'    => 'login',
                        'POST register' => 'register',
                    ]
                ],
                [
                    'class'      => yii\rest\UrlRule::className(),
                    'controller' => ['like', 'fans'],
                    'except'     => ['update', 'view'],
                    'pluralize'  => false,
                ],
                [
                    'class'      => yii\rest\UrlRule::className(),
                    'controller' => 'collect',
                    'except'     => ['update', 'view'],
                    'pluralize'  => false,

                ],
                [
                    'class'      => yii\rest\UrlRule::className(),
                    'controller' => ['comment'],
                ],

            ],
        ],
        'request'    => [
            'parsers'              => [
                'application/json' => 'yii\web\JsonParser',
                'text/json'        => 'yii\web\JsonParser',

            ],
            'enableCsrfValidation' => false,
            'cookieValidationKey'  => 'true',
        ],
        'response'   => [
            'format' => yii\web\Response::FORMAT_JSON,
        ],
    ],
    'modules'    => [
    ],
    'params'     => $params,
];
